package com.day03_class_object.test03_private;

/**
 * @ClassName: PrivateTest
 * @Author: 豆豆在睡觉
 * @Create 2024/2/25-14:08
 * @Version 1.0
 */

/**
 *  为了防止外部直接访问类内部的成员变量和方法，
 *  我们可以用private 修饰 变量 或者方法
 */
public class PrivateTest {
    private int age;
    public  PrivateTest() {}
    public PrivateTest(int age) {
        this.age = age;
    }
    public void setAge(int age) {
        if (age <=0 || age > 120) {
            System.out.println("设置年龄超出范围了");
        } else {
            this.age = age;
        }
    }
    public int getAge() {
        return this.age;
    }

    private void say() {
        System.out.println("sayhi");
    }

    public void getSay() {
        this.say();
    }
}
